# -*- coding: utf-8 -*-

"""
DateTime   : 2020/12/20 10:38
Author     : ZhangYafei
Description:
世界杯足球赛共有32支球队，分为8个小组，每组4支球队。小组赛采取循环赛，一场比赛后，获胜方得3分，失败方得0分，
若为平局，双方各得1分。试编写一个程序输出小组赛比赛所有可能的结果，要求如下：
1）按小组总得分从高到低排序输出；
2）每个小组输出成绩的格式为：
总得分=第一名得分+第二名得分+第三名得分+第四名得分
"""
""" 方法1 """
"""
score_list = [(3, 0), (0, 3), (1, 1)]

game_scores = set()

for team1A, team1B in score_list:
    for team1C, team1D in score_list:
        for team2A, team2C in score_list:
            for team2B, team2D in score_list:
                for team3A, team3D in score_list:
                    for team3B, team3C in score_list:
                         teamA = team1A + team2A + team3A
                         teamB = team1B + team2B + team3B
                         teamC = team1C + team2C + team3C
                         teamD = team1D + team2D + team3D
                         game_score_case = [teamA, teamB, teamC, teamD]
                         game_score_case.sort(reverse=True)
                         # if teamA == 9:
                         #    print(game_score_case, team1A, team1B, team1C, team1D, team2A, team2C, team2B, team2D, team3A, team3D, team3B, team3C)
                         game_scores.add(tuple(game_score_case))

game_scores = list(game_scores)
game_scores.sort(key=lambda x: sum(x), reverse=True)

for A, B, C, D in game_scores:
    score_sum = A + B + C + D
    print(f'{score_sum} = {A} + {B} + {C} + {D}')

# for game_score_case in game_scores:
#     add_string = ' + '.join(str(num) for num in game_score_case)
#     print(f'{sum(game_score_case)} = {add_string}')
#     game_scores.append([teamA, teamB, teamC, teamD]
"""
"""方法2 """
"""
from itertools import product  # product 生成指定序列的排列组合

score_list = [(3, 0), (0, 3), (1, 1)]

game_scores = set()

for game1, game2, game3, game4, game5, game6 in product(score_list, repeat=6):
    team1A, team1B = game1
    team1C, team1D = game2
    team2A, team2C = game3
    team2B, team2D = game4
    team3A, team3D = game5
    team3B, team3C = game6
    teamA = team1A + team2A + team3A
    teamB = team1B + team2B + team3B
    teamC = team1C + team2C + team3C
    teamD = team1D + team2D + team3D
    game_score_case = [teamA, teamB, teamC, teamD]
    game_score_case.sort(reverse=True)
    game_scores.add(tuple(game_score_case))

game_scores = list(game_scores)
game_scores.sort(key=lambda x: sum(x), reverse=True)

for A, B, C, D in game_scores:
    score_sum = A + B + C + D
    print(f'{score_sum} = {A} + {B} + {C} + {D}')
"""
from itertools import product  # product 生成指定序列的排列组合
from collections import defaultdict

score_list = [(3, 0), (0, 3), (1, 1)]

game_scores = defaultdict(set)

for game1, game2, game3, game4, game5, game6 in product(score_list, repeat=6):
    team1A, team1B = game1
    team1C, team1D = game2
    team2A, team2C = game3
    team2B, team2D = game4
    team3A, team3D = game5
    team3B, team3C = game6
    teamA = team1A + team2A + team3A
    teamB = team1B + team2B + team3B
    teamC = team1C + team2C + team3C
    teamD = team1D + team2D + team3D
    game_score_case = [teamA, teamB, teamC, teamD]
    game_score_case.sort(reverse=True)
    game_scores[sum(game_score_case)].add(tuple(game_score_case))

for score in game_scores:
    game_score_list = sorted(game_scores[score], reverse=True)
    for A, B, C, D in game_score_list:
        score_sum = A + B + C + D
        print(f'{score_sum} = {A} + {B} + {C} + {D}')
